#ifndef __MUTEX_LOCK_H_
#define __MUTEX_LOCK_H_

#include <pthread.h>

class MutexLock
{
public:
	MutexLock()
	{
		pthread_mutex_init(&_lock , NULL);
	}
	
	~MutexLock(void)
	{
		pthread_mutex_destroy(&_lock);	
	}
	
	void Lock()
	{
		pthread_mutex_lock(&_lock);
	}
	
	void UnLock()
	{
		pthread_mutex_unlock(&_lock);
	}
	
	pthread_mutex_t* GetMutex() 
	{
		 return &_lock; 
	}

private:
	pthread_mutex_t _lock;
};

//AutoLock

class AutoLock
{
public:
	explicit AutoLock( MutexLock &lock ) : _lock(lock)
	{
		_lock.Lock();
	}
	
	~AutoLock()
	{
		_lock.UnLock();
	}
	
private:
	MutexLock& _lock;
};



#endif
